import random as ran
import numpy as np




def removePercentOfList(ratio,inList):
    n=float(len(inList))
    result=(n/100)* float(ratio)
    toremove=ran.sample(inList,int(result))
    #print "removed:%s/%s" % (len(toremove),int(n))
    for i in toremove: inList.remove(i)
    #print "removed %s" % int(result)
    return inList

def hirePercentageOfPop(inpop,ratio):
    dice=float("%.2f"%ran.random())   
    un= [  x for x in inpop if (x.employment is "unemployed") ]
    if dice<=ratio:
        n=float(len(un))
        result=(n/100)* float(ratio)
        tohire=ran.sample(un,int(result))
        for i in tohire: 
            i.hire()
        #print "hired %s" % len(tohire)
    return inpop

def findTrend(data):
    values= map(lambda x: int(x[1]),data)
    changes=[]
    previous=0
    for i in values:
        if i==0: 
            previous=i
            pass
        else:
            diff= i-previous
            changes.append(diff)
            previous=i
    changes.remove(changes[0])
    return np.average(changes)